package game.leon.war.game;

import game.leon.engine.utils.LinkedNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * User: bianpeng
 * Date: 12-1-12
 */
@Component
public class GameConsumer {
    private ExecutorService executorService = Executors.newSingleThreadExecutor();
    @Autowired
    private GameHandlerService gameHandlerService;
    private void handle(final GameMessage message) {
        executorService.submit(new Runnable() {
            @Override
            public void run() {
                gameHandlerService.handle(message);
            }
        });
    }
    public void consume(LinkedNode<GameMessage> message) {
        while (message != null) {
            handle(message.getItem());
            message = message.getNext();
        }
    }
}
